var projectName = '/' + window.location.pathname.split('/')[1];
var userUrl = {
    'listUrl' : projectName + '/base/listUser.do'
};

var helloModule = angular.module('helloAngular', []);

helloModule.controller('InvoiceCntl', function($scope, $http) {
	$scope.qty = 1;
    $scope.cost = 19.95;
    
    $scope.users = [{name: "user1", age: "12"}, {name: "user2", age: "10"}, {name: "user3", age: "26"}, {name: "abc", age: "11"}];
    
    $http.post(userUrl.listUrl).success(function(data) {
    	$scope.userList = data;
    });
    
});

function userCntl() {
	
}

helloModule.directive('draggable', function($document) {
    var startX=0, startY=0, x = 0, y = 0;
    return function(scope, element, attr) {
      element.css({
       position: 'relative',
       border: '1px solid red',
       backgroundColor: 'lightgrey',
       cursor: 'pointer'
      });
      element.bind('mousedown', function(event) {
        startX = event.screenX - x;
        startY = event.screenY - y;
        $document.bind('mousemove', mousemove);
        $document.bind('mouseup', mouseup);
      });

      function mousemove(event) {
        y = event.screenY - startY;
        x = event.screenX - startX;
        element.css({
          top: y + 'px',
          left:  x + 'px'
        });
      }

      function mouseup() {
        $document.unbind('mousemove', mousemove);
        $document.unbind('mouseup', mouseup);
      }
    }
 });

helloModule.directive('hello', function() {  
    return {
	    restrict: "E",
	    replace: true,
	    template: "<div>Hello readers, thank you for coming</div>" 
    }  
});